home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
051-075
/
scopedisk70
/
edible
/
edible.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-19
|
3KB
|
69 lines
/***************************************************************************
* This simple utility was written 20-Dec-87 by J. Christopher Redden *
* (214) 221-1619 248 Southwest Pkwy #1012 Lewisville, Tx. 75067 *
* GEnie address J.REDDEN *
* I like to use ED, however, it is VERY frustrating to dload/capture *
* only to find that SOMEWHERE there is a binary that ED doesn't like. *
* This will write from argv[1] to argv[2] while filtering unwanted chars *
* as it goes. There is a third argument that will define the maximum *
* line length to be 1 to 255. If argv[3] == 0 then all the line length *
* counter is ignored and lines can be as long as you like. If there is *
* no argv[3] then a default value of 78 is set. *
* Things to add: BACKSPACE handler; Window to show what and where is being*
* filtered out; TAB handler; stuff like that... This will do for now. *
**************************************************************************/
# include <stdio.h>
# define LFEED 0x0A
# define RETURN 0x0D
# define SPACE 0x20
# define DELETE 0x7F
# define SETLENGTH 78 /* default setting for maximum line length */
int maxlen = 0, len = 0;
main (argc, argv)
int argc;
char *argv[];
{
int c;
FILE *fp1, *fp2, *fopen();
if (argc < 3) { /* check to see there are at LEAST infile and outfile */
printf("USAGE: EDible <input file> <output file> [LineLength DEFAULT= 77, 0= disable]\n");
exit(1); }
else if ((fp1 = fopen(argv[1],"r")) == NULL) { /* does infile exist */
printf("I don't see %s\n",argv[1]);
exit(1); }
else {
printf("Making %s O.K. for ED as file: %s\n",argv[1],argv[2]);
fp2 = fopen(argv[2],"w"); /* everything's OK, open outfile */
}
if (argc > 3) /* is there a third argument? */
sscanf(argv[3],"%d", &maxlen); /* change from character to decimal */
else
maxlen = SETLENGTH; /* No third argument. Set it to default */
{
while ((c = getc(fp1)) != EOF)
if ((c == LFEED) || (c == RETURN) || (c >= SPACE && c < DELETE)) {
if (++len == maxlen) { /* if maxlen=0 this will never be true */
len = 0; /* if true reset len (line length counter) */
putc(LFEED, fp2); } /* force a linefeed into outfile */
if(c == LFEED || c == RETURN)/* if there is a line terminator */
len = 0; /* reset line length counter */
if (len > 512) /* prevent overflow if maxlen=0 */
len = 0;
putc(c, fp2); /* pass input character to output file no matter what */
}
}
fclose(fp1); /* clean up and close up */
fclose(fp2);
}